package com.yc.dygang.junit;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class TestRunner {

    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException {
        TestRunner a = new TestRunner();
        // 扫描所有的类， 只要类中包含加了 @Test 方法
        Class<Demo> demoClass = Demo.class;

        //反射获取所有的公有方法,不含参数
        Method[] methods = demoClass.getDeclaredMethods();

        //通过注解筛选出bofore,after,test
        //分别保存到集合中
        
        //循环test方法集合
        for (Method method : methods) {
            if (method.isAnnotationPresent(Before.class)){
                method.invoke(a);
            }
            if (method.isAnnotationPresent(Test.class)){
                Test test = (Test) method.getDeclaredAnnotation(Test.class);
                int order = test.order();
                

            }
            if (method.isAnnotationPresent(After.class)){
                method.invoke(a);
            }
        }
        //先执行before
        //在执行 test
        //==》AssertError =》断言错误  => 测试结果错误
        //==>Exception  ==》 方法异常
        //==>正常执行结束 ==>正确
        //最后执行after


        //报告结果
    }
}
